﻿/**  版本信息模板在安装目录下，可自行修改。
* hars_notifyhistask.cs
*
* 功 能： N/A
* 类 名： hars_notifyhistask
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2017/11/9 13:48:33   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;

namespace PreeRegisterDAL
{
	/// <summary>
	/// 数据访问类:hars_notifyhistask
	/// </summary>
	public partial class hars_notifyhistask
	{
		public hars_notifyhistask()
		{}
		#region  BasicMethod

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperMySQL.GetMaxID("id", "hars_notifyhistask"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from hars_notifyhistask");
			strSql.Append(" where id=@id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id", MySqlDbType.Int32)
			};
			parameters[0].Value = id;

			return DbHelperMySQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(PreeRegisterModel.hars_notifyhistask model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into hars_notifyhistask(");
			strSql.Append("orderno,request,response,state,createdate,lastdate)");
			strSql.Append(" values (");
			strSql.Append("@orderno,@request,@response,@state,@createdate,@lastdate)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@orderno", MySqlDbType.VarChar,200),
					new MySqlParameter("@request", MySqlDbType.VarChar,1000),
					new MySqlParameter("@response", MySqlDbType.VarChar,20000),
					new MySqlParameter("@state", MySqlDbType.Int32,2),
					new MySqlParameter("@createdate", MySqlDbType.Timestamp),
					new MySqlParameter("@lastdate", MySqlDbType.Timestamp)};
			parameters[0].Value = model.orderno;
			parameters[1].Value = model.request;
			parameters[2].Value = model.response;
			parameters[3].Value = model.state;
			parameters[4].Value = model.createdate;
			parameters[5].Value = model.lastdate;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(PreeRegisterModel.hars_notifyhistask model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update hars_notifyhistask set ");
			strSql.Append("orderno=@orderno,");
			strSql.Append("request=@request,");
			strSql.Append("response=@response,");
			strSql.Append("state=@state");
			strSql.Append(" where id=@id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@orderno", MySqlDbType.VarChar,200),
					new MySqlParameter("@request", MySqlDbType.VarChar,1000),
					new MySqlParameter("@response", MySqlDbType.VarChar,20000),
					new MySqlParameter("@state", MySqlDbType.Int32,2),
					new MySqlParameter("@id", MySqlDbType.Int32,50)};
			parameters[0].Value = model.orderno;
			parameters[1].Value = model.request;
			parameters[2].Value = model.response;
			parameters[3].Value = model.state;
			parameters[4].Value = model.id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from hars_notifyhistask ");
			strSql.Append(" where id=@id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id", MySqlDbType.Int32)
			};
			parameters[0].Value = id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from hars_notifyhistask ");
			strSql.Append(" where id in ("+idlist + ")  ");
			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

        public bool Update(string state, string orderid, string response)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update hars_notifyhistask set ");
            strSql.Append("state=@state,");
            strSql.Append("lastdate=@lastdate,");
            strSql.Append("response=@response");
            strSql.Append(" where orderno=@orderno");
            MySqlParameter[] parameters = {
                    new MySqlParameter("@state", MySqlDbType.Int32,2),
                    new MySqlParameter("@lastdate", MySqlDbType.Timestamp),
                    new MySqlParameter("@response", MySqlDbType.VarChar,20000),
                    new MySqlParameter("@orderno", MySqlDbType.VarChar,50)};
            parameters[0].Value = state;
            parameters[1].Value = DateTime.Now;
            parameters[2].Value = response;
            parameters[3].Value = orderid ;

            int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public PreeRegisterModel.hars_notifyhistask GetModel(int id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id,orderno,request,response,state,createdate,lastdate from hars_notifyhistask ");
			strSql.Append(" where id=@id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id", MySqlDbType.Int32)
			};
			parameters[0].Value = id;

            PreeRegisterModel.hars_notifyhistask model=new PreeRegisterModel.hars_notifyhistask();
			DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public PreeRegisterModel.hars_notifyhistask DataRowToModel(DataRow row)
		{
            PreeRegisterModel.hars_notifyhistask model=new PreeRegisterModel.hars_notifyhistask();
			if (row != null)
			{
				if(row["id"]!=null && row["id"].ToString()!="")
				{
					model.id=int.Parse(row["id"].ToString());
				}
				if(row["orderno"]!=null)
				{
					model.orderno=row["orderno"].ToString();
				}
				if(row["request"]!=null)
				{
					model.request=row["request"].ToString();
				}
				if(row["response"]!=null)
				{
					model.response=row["response"].ToString();
				}
				if(row["state"]!=null && row["state"].ToString()!="")
				{
					model.state=int.Parse(row["state"].ToString());
				}
				if(row["createdate"]!=null && row["createdate"].ToString()!="")
				{
					model.createdate=DateTime.Parse(row["createdate"].ToString());
				}
				if(row["lastdate"]!=null && row["lastdate"].ToString()!="")
				{
					model.lastdate=DateTime.Parse(row["lastdate"].ToString());
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id,orderno,request,response,state,createdate,lastdate ");
			strSql.Append(" FROM hars_notifyhistask ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM hars_notifyhistask ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
            object obj = DbHelperMySQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.id desc");
			}
			strSql.Append(")AS Row, T.*  from hars_notifyhistask T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "hars_notifyhistask";
			parameters[1].Value = "id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

